package com.etpjava.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.etpjava.model.Employee;
import com.etpjava.model.Train;
import com.etpjava.service.TrainService;
import com.etpjava.service.impl.TrainServiceImpl;
import com.etpjava.util.GetSth;
import com.etpjava.util.Page;

public class TrainAction{
	static Log logger = LogFactory.getLog(GetSth.class);
	private Train train;
	private Integer id;
	private String title;
	private int[] ids;
	private String content;
	private Date time;
	private String name;
    private String address;
	private List<Employee> employees;
	private List<Train> trains;
	TrainService trainser=new TrainServiceImpl();
	private Integer id1;
	private Integer id2;
	private int pagenum;
	private Page pagelist;
	
	public String fuzzy(){
		if(pagelist==null){
			pagelist=new Page(1);
		}
		pagelist.setActionname("fuzzy");
		HashMap<String,String> sw=new HashMap<String,String>();
		if(id1!=null){
			sw.put("id1", GetSth.change(String.valueOf(id1)));
		}
		if(id2!=null){
			sw.put("id2", GetSth.change(String.valueOf(id2)));
		}
		trainser.findByIdRange(sw,pagelist);
//		this.pager=trainser.findByIdRange(id1, id2,pagenum);
//		trains=pager.getList();
		return "list";
	}
	
	
	public String fuzzyMany(){
		if(pagelist==null){
			pagelist=new Page(1);
		}
		pagelist.setActionname("fuzzyMany");
//		String Ttime=GetSth.fDate(time, "yyyy-MM-dd");
		HashMap<String,String> sw=new HashMap<String, String>();
//		sw.put("time", Ttime);
		if(null!=id){
	      sw.put("id", GetSth.change(String.valueOf(id)));
		}
		if(null!=content){
		  sw.put("content", GetSth.change(content));
		}
		if(null!=title){
		  sw.put("title", GetSth.change(title));
		}
		if(null!=address){
		  sw.put("address", GetSth.change(address));
		}
		trainser.findFuzzyForPage(pagelist, sw);
		
//		this.pager=trainser.findFuzzyForPage(sw, pagenum);
//		trains=pager.getList();
		return "list";
	}
	
//	String birth=GetSth.getDate(age);
//	Map<String,String> sw=new HashMap<String,String>();
//	sw.put("birth",birth);
//    sw.put("name", name);
//	sw.put("profession", profession);
//    sw.put("education", education);
//	this.pager=invite.findFuzzyForPage(sw,page);
//	return "list";
//	public String showEmploy(){
//		logger.info(id);
//		train=trainser.findById(id);
//		logger.info(train.getMyEmployees());
//		Iterator<?> it=train.getMyEmployees().iterator();
//		while(it.hasNext()){
//			Employee employee=(Employee) it.next();
//			employees.add(employee);
//		}
//		
//		return "employ";
//	}
	
	
	public String deleteById(){
		trainser.delete(id);
		return "delete";
		
		
	}
	public String deletese() {//����ɾ���¼
		if (ids!=null&&ids.length!=0) {
			for (int id :ids) {
				trainser.delete(id);
			}
		}
	  return "deletemany";
	}
	
//	

	public String findByTitle(){
		if(pagelist==null){
			pagelist=new Page(1);
		}
		pagelist.setActionname("findByTitle");
		trainser.findByTitle(pagelist,GetSth.change(title));
//		trains=trainser.findByTitle(title);
//		this.pager=trainser.findByTitle(title, pagenum);	
//		trains=pager.getList();
		 return "list";
     } 
	
	public String detail(){
		train=trainser.findById(id);
		System.out.println(train.getContent());
		System.out.println(train.getContent());
		return "detail";
	}
	
    /**
     * @ ��ҳ�������м�¼
     * @return
     */

	public String findAll(){
    	if(pagelist==null)
    	{
    		pagelist=new Page(1);
    	}
    	pagelist.setActionname("findAll");
    	trainser.findAll(pagelist);
//    	this.pager=trainser.findAll(pagenum);
//    	trains=pager.getList();
    	return "list";
    	
    }
	public String findByIds(){
		if(pagelist==null){
			pagelist=new Page(1);
			
		}
		pagelist.setActionname("findByIds");
		
		trains=trainser.findByIds(id);
		pagelist.setList(trains);
		pagelist.setRowTotalCount(1);
		return "list";
		
	}
	
	public String addTrain(){
		if(null!=id){
			
			trainser.modifyTrain(train);
			
		}else{
		   trainser.addTrain(train);
		 
		}
		return "modify";
	}

	public Train getTrain() {
		return train;
	}

	public Integer getId() {
		return id;
	}

	public void setTrain(Train train) {
		this.train = train;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public List<Train> getTrains() {
		return trains;
	}

	public void setTrains(List<Train> trains) {
		this.trains = trains;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}


	public int[] getIds() {
		return ids;
	}


	public void setIds(int[] ids) {
		this.ids = ids;
	}


	public List<Employee> getEmployees() {
		return employees;
	}


	public void setEmployees(List<Employee> employees) {
		this.employees = employees;
	}


	public String getContent() {
		return content;
	}


	public Date getTime() {
		return time;
	}


	public String getName() {
		return name;
	}


	public String getAddress() {
		return address;
	}


	public void setContent(String content) {
		this.content = content;
	}


	public void setTime(Date time) {
		this.time = time;
	}


	public void setName(String name) {
		this.name = name;
	}


	public void setAddress(String address) {
		this.address = address;
	}


	public Integer getId1() {
		return id1;
	}


	public Integer getId2() {
		return id2;
	}


	public void setId1(Integer id1) {
		this.id1 = id1;
	}


	public void setId2(Integer id2) {
		this.id2 = id2;
	}


	public int getPagenum() {
		return pagenum;
	}


	

	public void setPagenum(int pagenum) {
		this.pagenum = pagenum;
	}



	public Page getPagelist() {
		return pagelist;
	}

	public void setPagelist(Page pagelist) {
		this.pagelist = pagelist;
	}


	


	

}
